package mumu.android.localstorage;

import mumu.android.R;
import mumu.android.lib.tool.MLog;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

public class shared extends DialogFragment {

	static shared instance;

	public static shared getInstance() {
		if (instance == null) {
			instance = new shared();
		}
		return instance;
	}

	@Override
	public void dismiss() {
		super.dismiss();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
	}

	Dialog dialog;
	TextView txt;

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		MLog.d("dds", "onCreateDialog");
		if (dialog == null) {
			MLog.d("dds", "onCreateDialog_dialog");
			dialog = new Dialog(getActivity(), R.style.dialog);
			LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
			View view = layoutInflater.inflate(R.layout.dialog_listview, null);
			view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			dialog.setContentView(R.layout.dialog_listview);
			dialog.setCanceledOnTouchOutside(true);
			new ApkSharedPreferences(getActivity()).setKEY_1(false);
			new ApkSharedPreferences(getActivity()).setKEY_2("mystest");
			new ApkSharedPreferences(getActivity()).setKEY_3(10);
			new ApkSharedPreferences(getActivity()).setKEY_4(20.02f);
			new ApkSharedPreferences(getActivity()).setKEY_5(5000L);
		} else {
			txt.setText("Wuhan");
		}
		return dialog;
		// return super.onCreateDialog(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		MLog.d("dds", "onCreateView");
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	public class ApkSharedPreferences {

		private SharedPreferences getShare;

		public ApkSharedPreferences(Context c) {
			// Context.MODE_PRIVATE这个属性表明它是私有的，不能被其他进程所访问，可以指定Context.MODE_WORLD_READABLE和Context.MODE_WORLD_WRITEABLE权限，让其他应用访问到，不过一般我不会使用这两个属性。
			getShare = c.getSharedPreferences("mytestshared", Context.MODE_PRIVATE);
		}

		public void setKEY_2(String s) {
			getShare.edit().putString("KEY_2", s).commit();
		}

		public void setKEY_3(Integer s) {
			getShare.edit().putInt("KEY_3", s).commit();
		}

		public void setKEY_1(Boolean s) {
			getShare.edit().putBoolean("KEY_1", s).commit();
		}

		public void setKEY_4(Float s) {
			getShare.edit().putFloat("KEY_4", s).commit();
		}

		public void setKEY_5(Long s) {
			getShare.edit().putLong("KEY_5", s).commit();
		}

		public Long getKey_5() {
			return getShare.getLong("KEY_5", 0L);
		}

	}

}
